<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>字符串类型</title>
  <script>
    function f1(){
let s="Hello World";
console.log("字符串长度:"+s.length);
//去除首尾空格
      s.trim();
      console.log("字符串长度:"+s.length)
      console.log("转大写:"+s.toUpperCase)
      console.log("转小写:"+s.toLowerCase)
      console.log("获取索引位置为7的字符:"+s.charAt(7))
    }
    // 转为整数
    function f2(){
      // let s = "123";
      // let s = "123.45";
      // let s = "123abc";
      // let s = "123abc45";
      // let s = "123.45.67";
      let s = "a123";
      //转译遇到非数字开始停止
      let num = parseInt(s);
      console.log(num)
    }
    // 转为小写
    function f3(){
      // let s = "123.45";
      // let s = "123.45.67";
      // let s = "123a.67";
      let s = "a123a.67";
      //和转大写的区别是第一个小数点可以识别
      let num = parseFloat(s);
      console.log(num)
    }
    // 截取字符串（左闭右开）
    function f4(){
      let s = "Hello World,I am admin";
      // console.log(s.substring(7))
      console.log(s.substring(7,15))
    }
    // 字符串常用方法
    function f5(){
      let s = "admin and jack and tom and lucy";
      console.log(s.length)
      console.log("and第一次出现的索引位置:"+s.indexOf("and"))
      console.log("and最后一次出现的索引位置:"+s.lastIndexOf("and"))
      console.log(s.replace("and","-"))
      console.log(s.replaceAll("and","-"))
    }
  </script>
</head>
<body>
<button onclick="f1()">常用方法</button><br>
<button onclick="f2()">转整数</button><br>
<button onclick="f3()">转小数</button><br>
<button onclick="f4()">截取字符串</button><br>
<button onclick="f5()">获取索引位置</button>
</body>
</html>